/**
 * StringUtil.java
 * jp.co.greenblue.framework.util
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 2010/11/03 		jonsion
 *
 * Copyright (c) 2010, GreenBlue .  All Rights Reserved.
*/

package jp.co.greenblue.framework.util;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

/**
 * ClassName:StringUtil
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   jonsion
 * @version  
 * @since    Ver 1.1
 * @Date	 2010/11/03		14:14:06
 *
 * @see 	 
 */
public class StringUtil {
	/**
	 * <b>返回一个指定位数的小数，并进行四舍五入</b><br>
	 * 
	 * @author liyujun<br>
	 *         <b>create Date:</b>2009/09/05 9:51:43<br>
	 *         <b>last modify Date:</b>2009/09/05 9:51:43<br>
	 * @param var
	 *            数值型字符串
	 * @param bit
	 *            保留小数点位数
	 * @return
	 */
	public static float floatRound(String var, int bit) {
		float temValue = 1;
		String temp = "1";
		for (int i = 0; i < bit; i++) {
			if (i == 0) {
				temp = "0.1";
			} else {
				temp = temp.substring(0, temp.indexOf(".") + 1) + "0"
						+ temp.substring(temp.indexOf(".") + 1);
			}
		}
		temValue = Float.parseFloat(temp);
		if (var == null || var.equals(""))
			return 0;
		else {
			String tempFloat = String.valueOf(Math.round(Float.parseFloat(var)
					/ temValue));
			if (bit == 0) {
			} else if (tempFloat.length() > bit) {
				tempFloat = tempFloat.substring(0, tempFloat.length() - bit)
						+ "." + tempFloat.substring(tempFloat.length() - bit);
			} else if (tempFloat.length() == bit) {
				tempFloat = "0." + tempFloat;
			} else {
				for (int i = 0; i < bit - tempFloat.length(); i++) {
					tempFloat = "0" + tempFloat;
				}
				tempFloat = "0." + tempFloat;
			}

			return Float.parseFloat(tempFloat);
		}
	}

	/**
	 * <b>固定長の文字列を取得する</b><br>
	 * 開発者：wangli<br>
	 * 開発時間：2007/10/15<br>
	 * 更新時間：2008/01/23<br>
	 * 
	 * @param str
	 *            元文字列
	 * @param fixedLength
	 *            固定文字列の長さ
	 * @param fillingChar
	 *            充填の文字
	 * @return 固定長の文字列
	 */
	public static String padLeft(String str, int fixedLength, char fillingChar) {
		if (str == null) {
			str = "";
			int space = fixedLength;
			while (space-- != 0) {
				str = fillingChar + str;
			}
			return str;
		}
		if (str.length() < fixedLength) {
			int space = fixedLength - str.length();
			while (space-- != 0) {
				str = fillingChar + str;
			}
		}
		return str;
	}

	/**
	 * <b>固定長の文字列を取得する</b><br>
	 * 開発者：wangli<br>
	 * 開発時間：2007/10/15<br>
	 * 更新時間：2008/01/23<br>
	 * 
	 * @param str
	 *            元文字列
	 * @param fixedLength
	 *            固定文字列の長さ
	 * @param fillingChar
	 *            充填の文字
	 * @return 固定長の文字列
	 */
	public static String padRight(String str, int fixedLength, char fillingChar) {
		if (str == null) {
			str = "";
			int space = fixedLength;
			while (space-- != 0) {
				str = str + fillingChar;
			}
			return str;
		}
		if (str.length() < fixedLength) {
			int space = fixedLength - str.length();
			while (space-- != 0) {
				str = str + fillingChar;
			}
		}
		return str;
	}

	/**
	 * 根據傳入的字符串，剪切左邊的字符串，使其保留長度為keepLength，如果傳入字符串小于等於keepLength，則返回原字符串
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Aug 18, 2009 11:48:48 AM<br>
	 *         <b>last modify Date:</b>Aug 18, 2009 11:48:48 AM<br>
	 * @param str
	 *            參數為空時返回“”
	 * @param keepLength
	 *            保留字符串的長度
	 * @return String 如：str:"123456" keepLength:4 則返回："3456";str:"123"
	 *         keepLength:4 則返回:"123"
	 */

	public static String cutLeft(String str, int keepLength) {
		String result = str;
		if (keepLength <= 0)
			return "";
		if (str != null && !"".equals(str)) {
			if (str.length() > keepLength) {
				if (str.length() > keepLength) {
					result = str.substring(str.length() - keepLength);
				}
			}
		}
		return result;
	}

	/**
	 * 根據傳入的字符串，剪切右邊的字符串，使其保留長度為keepLength，如果傳入字符串小于等於keepLength，則返回原字符串
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Aug 18, 2009 11:48:46 AM<br>
	 *         <b>last modify Date:</b>Aug 18, 2009 11:48:46 AM<br>
	 * @param str
	 *            參數為空時返回“”
	 * @param keepLength
	 *            保留字符串的長度
	 * @return String 如：str:"123456" keepLength:4 則返回："1234";str:"123"
	 *         keepLength:4 則返回:"123"
	 */

	public static String cutRitht(String str, int keepLength) {
		String result = str;
		if (keepLength <= 0)
			return result;
		if (str != null && !"".equals(str)) {
			if (str.length() > keepLength) {
				result = str.substring(0, keepLength);
			}
		}
		return result;
	}

	/**
	 * 将传进来的数字格式化成length长度的字符串，不足补‘0’,如数字长度大于length则返回原来长度的字符串
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Aug 18, 2009 10:15:06 AM<br>
	 *         <b>last modify Date:</b>Aug 18, 2009 10:15:06 AM<br>
	 * @param value
	 * @param length
	 * @return String 如参数：value:10 length:4 则返回"0010";
	 */

	public static String formatNumber(int value, int length) {
		String result = String.valueOf(value);
		result = padLeft(result, length, '0');
		return result;
	}

	public static String trim(String tmp) {
		String result = "";
		if (tmp != null && tmp != "") {
			result = tmp.trim();
		}
		return result;
	}

	public static int length(String tmp) {
		int length = 0;
		if (tmp != null && tmp != "") {
			length = tmp.trim().length();
		}
		return length;
	}

	/**
	 * 如果字符串为""则返回replace，如果字符串不为空 <b>create Date:</b>2010/01/18 10:25:42<br>
	 * <b>last modify Date:</b>2010/01/18 10:25:42<br>
	 * 
	 * @param tmp
	 * @param replace
	 * @return
	 */

	public static String trimWileNullReplace(String tmp, String replace) {
		String result = replace;
		if (tmp != null && tmp != "") {
			result = tmp.trim();
		}

		if (tmp == null) {
			result = replace;
		}
		return result;
	}

	/**
	 * 如果字符串为""则返回replace，如果字符串不为空，在其前后加上字符串appendstr <b>create Date:</b>2010/01/18
	 * 10:24:49<br>
	 * <b>last modify Date:</b>2010/01/18 10:24:49<br>
	 * 
	 * @param tmp
	 * @param replace
	 * @param appendstr
	 * @return
	 */

	public static String trimWileNullReplace(String tmp, String replace,
			String appendstr) {
		String result = "";
		result = trimWileNullReplace(tmp, replace);
		if (result != null) {
			StringBuffer resultstr = new StringBuffer();
			resultstr.append(appendstr);
			resultstr.append(result);
			resultstr.append(appendstr);
			return resultstr.toString();
		}
		return result;
	}

	/**
	 * @author liyujun
	 * @see 該方法為將傳入對象中所有為STRING的屬性去空格，返回值為該對象中所有為STRING的屬性的都已去除空格。(如果String值为""，则把值转换为null)
	 * @param obj
	 * @return Object
	 */
	@SuppressWarnings("unchecked")
//	public static Object trimNull(Object obj) {
//		if (obj != null) {
//			if (obj instanceof Map) {
//				Map tmpMap = (Map) obj;
//				if (tmpMap.size() != 0) {
//					Set tmpSet = tmpMap.entrySet();
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						String key = (String) iterator.next();
//						Object tmpobj = tmpMap.get(key);
//						tmpMap.remove(key);
//						tmpMap.put(key, StringUtil.trimObject(tmpobj, 2, null));
//					}
//				}
//				return tmpMap;
//			} else if (obj instanceof List) {
//				List tmpList = (List) obj;
//				if (tmpList.size() != 0) {
//					for (int i = 0; i < tmpList.size(); i++) {
//						Object tmpobj = tmpList.get(i);
//						tmpList.set(i, StringUtil.trimObject(tmpobj, 2, null));
//					}
//
//				}
//				return tmpList;
//			} else if (obj instanceof Set) {
//				Set tmpSet = (Set) obj;
//				if (tmpSet.size() != 0) {
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						Object tmpobj = iterator.next();
//						tmpSet.remove(tmpobj);
//						tmpSet.add(StringUtil.trimObject(tmpobj, 2, null));
//					}
//				}
//				return tmpSet;
//			} else {
//				return StringUtil.trimObject(obj, 2, null);
//			}
//		}
//		return null;
//	}

	public static void trim(List<List<String>> resultListList){
		if(resultListList!=null && resultListList.size()!=0){
			for(List<String> tmpList:resultListList){
				for(int i=0;i<tmpList.size();i++){
					tmpList.set(i, StringUtil.trim(tmpList.get(i)));
				}
			}
		}
	}
	
	/**
	 * @author jiangxc
	 * @see 該方法為將傳入對象中所有為STRING的屬性去空格，返回值為該對象中所有為STRING的屬性的都已去除空格。
	 * @param obj
	 * @return Object
	 */

//	public static Object trim(Object obj) {
//		if (obj != null) {
//			if (obj instanceof Map) {
//				Map tmpMap = (Map) obj;
//				if (tmpMap.size() != 0) {
//					Set tmpSet = tmpMap.entrySet();
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						String key = (String) iterator.next();
//						Object tmpobj = tmpMap.get(key);
//						tmpMap.remove(key);
//						tmpMap.put(key, StringUtil.trimObject(tmpobj, 1, null));
//					}
//				}
//				return tmpMap;
//			} else if (obj instanceof List) {
//				List tmpList = (List) obj;
//				if (tmpList.size() != 0) {
//					for (int i = 0; i < tmpList.size(); i++) {
//						Object tmpobj = tmpList.get(i);
//						tmpList.set(i, StringUtil.trimObject(tmpobj, 1, null));
//					}
//
//				}
//				return tmpList;
//			} else if (obj instanceof Set) {
//				Set tmpSet = (Set) obj;
//				if (tmpSet.size() != 0) {
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						Object tmpobj = iterator.next();
//						tmpSet.remove(tmpobj);
//						tmpSet.add(StringUtil.trimObject(tmpobj, 1, null));
//					}
//				}
//				return tmpSet;
//			} else {
//				return StringUtil.trimObject(obj, 1, null);
//			}
//		}
//		return null;
//	}
//
//	/**
//	 * 該方法為將傳入對象中所有為STRING的屬性去空格，返回值為該對象中所有為STRING的屬性的都已去除空格。,如果obj對像中有字段為null且是String類型，則用nullString替換null。
//	 * 
//	 * @author jiangxc<br>
//	 *         <b>create Date:</b>Aug 19, 2009 4:10:00 PM<br>
//	 *         <b>last modify Date:</b>Aug 19, 2009 4:10:00 PM<br>
//	 * @param obj
//	 * @param nullString
//	 * @return
//	 */
//
//	@SuppressWarnings("unchecked")
//	public static Object trim(Object obj, String nullString) {
//		if (obj != null) {
//			if (obj instanceof Map) {
//				Map tmpMap = (Map) obj;
//				if (tmpMap.size() != 0) {
//					Set tmpSet = tmpMap.entrySet();
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						String key = (String) iterator.next();
//						Object tmpobj = tmpMap.get(key);
//						tmpMap.remove(key);
//						tmpMap.put(key, StringUtil.trimObject(tmpobj, 3,
//								nullString));
//					}
//				}
//				return tmpMap;
//			} else if (obj instanceof List) {
//				List tmpList = (List) obj;
//				if (tmpList.size() != 0) {
//					for (int i = 0; i < tmpList.size(); i++) {
//						Object tmpobj = tmpList.get(i);
//						tmpList.set(i, StringUtil.trimObject(tmpobj, 3,
//								nullString));
//					}
//
//				}
//				return tmpList;
//			} else if (obj instanceof Set) {
//				Set tmpSet = (Set) obj;
//				if (tmpSet.size() != 0) {
//					Iterator iterator = tmpSet.iterator();
//					while (iterator.hasNext()) {
//						Object tmpobj = iterator.next();
//						tmpSet.remove(tmpobj);
//						tmpSet
//								.add(StringUtil.trimObject(tmpobj, 3,
//										nullString));
//					}
//				}
//				return tmpSet;
//			} else {
//				return StringUtil.trimObject(obj, 3, nullString);
//			}
//		}
//		return null;
//	}

	/**
	 * 該方法為將傳入對象中所有為STRING的屬性去空格，返回值為該對象中所有為STRING的屬性的都已去除空格。
	 * 
	 * @author jiangxc
	 * @param obj
	 *            类型为普通object,非list,set,map
	 * @return Object
	 */
//	private static Object trimObject(Object obj, int type, String nullString) {
//		if (obj != null) {
//			if (obj instanceof Map) {
//				return null;
//			} else if (obj instanceof List) {
//				return null;
//			} else if (obj instanceof Set) {
//				return null;
//			} else {
//				Class tmpclass = obj.getClass();
//				Field[] tmpfield = tmpclass.getDeclaredFields();
//
//				Class baseTemClass = BaseBean.class;
//				Field[] baseTmpfield = baseTemClass.getDeclaredFields();
//				for (int i = 0; i < baseTmpfield.length; i++) {
//					Field baseField = baseTmpfield[i];
//					String fieldName = baseField.getName();
//					if (fieldName.equals("serialVersionUID"))
//						continue;
//					String backName = fieldName.substring(0, 1).toUpperCase()
//							+ fieldName.substring(1);
//					String getMethodName = "get" + backName;
//					String setMethodName = "set" + backName;
//
//					obj = StringUtil.objMethod(obj, getMethodName,
//							setMethodName, tmpclass, baseTmpfield, baseField,
//							i, type, nullString);
//				}
//
//				for (int i = 0; i < tmpfield.length; i++) {
//					Field field = tmpfield[i];
//					String fieldName = field.getName();
//					if (fieldName.equals("serialVersionUID"))
//						continue;
//					String backName = fieldName.substring(0, 1).toUpperCase()
//							+ fieldName.substring(1);
//					String getMethodName = "get" + backName;
//					String setMethodName = "set" + backName;
//					obj = StringUtil.objMethod(obj, getMethodName,
//							setMethodName, tmpclass, tmpfield, field, i, type,
//							nullString);
//				}
//
//				// add by zsy 20091211 在对父类的字段去一次空格。基本能满足去掉显示字段的空格问题。
//				tmpfield = obj.getClass().getSuperclass().getDeclaredFields();
//				for (int i = 0; i < tmpfield.length; i++) {
//					Field field = tmpfield[i];
//					String fieldName = field.getName();
//					if (fieldName.equals("serialVersionUID"))
//						continue;
//					String backName = fieldName.substring(0, 1).toUpperCase()
//							+ fieldName.substring(1);
//					String getMethodName = "get" + backName;
//					String setMethodName = "set" + backName;
//					obj = StringUtil.objMethod(obj, getMethodName,
//							setMethodName, tmpclass, tmpfield, field, i, type,
//							nullString);
//				}
//
//				return obj;
//			}
//		}
//		return null;
//	}

	/**
	 * @see 該方法為將傳入對象中指定方法的STRING的屬性去空格
	 * @author liyujun<br>
	 *         <b>create Date:</b>2009/09/10 14:42:48<br>
	 *         <b>last modify Date:</b>2009/09/10 14:42:48<br>
	 * @param obj
	 * @param getMethodName
	 * @param setMethodName
	 * @param tmpclass
	 * @param tmpfield
	 * @param field
	 * @param i
	 * @return
	 */

//	private static Object objMethod(Object obj, String getMethodName,
//			String setMethodName, Class tmpclass, Field[] tmpfield,
//			Field field, int i, int type, String nullString) {
//		Method getMethod, setMethod;
//		try {
//			getMethod = tmpclass.getMethod(getMethodName, new Class[] {});
//			Object value = getMethod.invoke(obj, new Object[] {});
//			if (value == null) {
//				if (type == 3) {
//					// if (value instanceof String) {
//					setMethod = tmpclass.getMethod(setMethodName,
//							new Class[] { field.getType() });
//					setMethod.invoke(obj, new Object[] { nullString });
//					// }
//				}
//				return obj;
//			}
//			if (value instanceof String) {
//				if (type == 2 && value.equals("")) {
//					value = null;
//				} else {
//					value = String.valueOf(value).trim();
//				}
//			}
//
//			if ("java.lang.String".equals(tmpfield[i].getType().getName())) {
//				setMethod = tmpclass.getMethod(setMethodName,
//						new Class[] { field.getType() });
//				setMethod.invoke(obj, new Object[] { value });
//			}
//
//		} catch (SecurityException e) {
//			// TODO Auto-generated catch block
//			// e.printStackTrace();
//		} catch (NoSuchMethodException e) {
//			// TODO Auto-generated catch block
//			// e.printStackTrace();
//		} catch (IllegalArgumentException e) {
//			// TODO Auto-generated catch block
//			// e.printStackTrace();
//		} catch (IllegalAccessException e) {
//			// TODO Auto-generated catch block
//			// e.printStackTrace();
//		} catch (InvocationTargetException e) {
//			// TODO Auto-generated catch block
//			// e.printStackTrace();
//		}
//		return obj;
//	}

	// /**
	// * @author jiangxc
	// * @see
	// 該方法為將傳入對象中所有為STRING的屬性去空格，返回值為該對象中所有為STRING的屬性的都已去除空格,如果obj對像中有字段為null且是String類型，則用nullString替換null。
	// * @param obj
	// * 类型为普通object,非list,set,map
	// * @return Object
	// */
	// @SuppressWarnings("unchecked")
	// private static Object trimObject(Object obj, String nullString) {
	// if (obj != null) {
	// if (obj instanceof Map) {
	// return null;
	// } else if (obj instanceof List) {
	// return null;
	// } else if (obj instanceof Set) {
	// return null;
	// } else {
	// Class tmpclass = obj.getClass();
	// Field[] tmpfield = tmpclass.getDeclaredFields();
	// for (int i = 0; i < tmpfield.length; i++) {
	// Field field = tmpfield[i];
	//
	// String fieldName = field.getName();
	// if (fieldName.equals("serialVersionUID"))
	// continue;
	// String backName = fieldName.substring(0, 1).toUpperCase()
	// + fieldName.substring(1);
	// String getMethodName = "get" + backName;
	// String setMethodName = "set" + backName;
	// Method getMethod, setMethod;
	// try {
	// getMethod = tmpclass.getMethod(getMethodName,
	// new Class[] {});
	// Object value = getMethod.invoke(obj, new Object[] {});
	// if (value == null) {
	// if (value instanceof String) {
	// setMethod = tmpclass.getMethod(setMethodName,
	// new Class[] { field.getType() });
	// setMethod.invoke(obj,
	// new Object[] { nullString });
	// }
	// continue;
	// }
	// if (value instanceof String) {
	// value = String.valueOf(value).trim();
	// }
	//
	// if ("java.lang.String".equals(tmpfield[i].getType()
	// .getName())) {
	// setMethod = tmpclass.getMethod(setMethodName,
	// new Class[] { field.getType() });
	// setMethod.invoke(obj, new Object[] { value });
	// }
	//
	// } catch (SecurityException e) {
	// // TODO Auto-generated catch block
	// // e.printStackTrace();
	// } catch (NoSuchMethodException e) {
	// // TODO Auto-generated catch block
	// // e.printStackTrace();
	// } catch (IllegalArgumentException e) {
	// // TODO Auto-generated catch block
	// // e.printStackTrace();
	// } catch (IllegalAccessException e) {
	// // TODO Auto-generated catch block
	// // e.printStackTrace();
	// } catch (InvocationTargetException e) {
	// // TODO Auto-generated catch block
	// // e.printStackTrace();
	// }
	// }
	// return obj;
	// }
	// }
	// return null;
	// }

	/**
	 * 根據傳入的數組轉換成以逗號分割的字符串
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Jul 7, 2009 10:45:50 AM<br>
	 *         <b>last modify Date:</b>Jul 7, 2009 10:45:50 AM<br>
	 * @param arrays
	 * @return String 例如"1,2,3,4,5,6"
	 */

	public static String array2String(String[] arrays) {
		String resultString = "";
		if (arrays != null && arrays.length != 0) {
			StringBuffer tmpstring = new StringBuffer();
			boolean flag = false;
			for (String tmps : arrays) {
				if ("".equals(tmps) || tmps == null)
					continue;
				if (flag)
					tmpstring.append(",");
				tmpstring.append(tmps.trim());
				flag = true;
			}
			resultString = tmpstring.toString();
		}
		return resultString;
	}

	/**
	 * 根據傳入的數組轉換成以逗號分割的字符串,并用appendChar把数组元素包起来
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Jul 7, 2009 10:45:50 AM<br>
	 *         <b>last modify Date:</b>Jul 7, 2009 10:45:50 AM<br>
	 * @param arrays
	 * @return String appendChar=' 例如"'1','2','3','4','5','6'"
	 */

	public static String array2StringAppend(String[] arrays, String appendChar) {
		String resultString = "";
		if (arrays != null && arrays.length != 0) {
			StringBuffer tmpstring = new StringBuffer();
			boolean flag = false;
			for (String tmps : arrays) {
				if ("".equals(tmps) || tmps == null)
					continue;
				if (flag)
					tmpstring.append(",");
				tmpstring.append(appendChar);
				tmpstring.append(tmps.trim());
				tmpstring.append(appendChar);
				flag = true;
			}
			resultString = tmpstring.toString();
		}
		return resultString;
	}

	/**
	 * 根據傳入的List<String>轉換成以逗號分割的字符串
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Jul 7, 2009 10:45:53 AM<br>
	 *         <b>last modify Date:</b>Jul 7, 2009 10:45:53 AM<br>
	 * @param stringlist
	 * @return String 例如"1,2,3,4,5,6"
	 */

	public static String list2String(List<String> stringlist) {
		String resultString = "";
		if (stringlist != null && stringlist.size() != 0) {
			StringBuffer tmpstring = new StringBuffer();
			boolean flag = false;
			for (String tmps : stringlist) {
				if ("".equals(tmps) || tmps == null)
					continue;
				if (flag)
					tmpstring.append(",");
				tmpstring.append(tmps.trim());
				flag = true;
			}
			resultString = tmpstring.toString();
		}
		return resultString;
	}

	/**
	 * 根據傳入的List<String>轉換成以逗號分割的字符串
	 * 
	 * @author zhangshiying<br>
	 *         <b>create Date:</b>2009/11/04 17:29:55<br>
	 *         <b>last modify Date:</b>2009/11/04 17:29:55<br>
	 * @param stringlist
	 * @return String 例如"1, , , , ,6"
	 */

	public static String listBlank2String(List<String> stringlist) {
		String resultString = "";
		if (stringlist != null && stringlist.size() != 0) {
			StringBuffer tmpstring = new StringBuffer();
			boolean flag = false;
			for (String tmps : stringlist) {
				if (tmps == null)
					continue;
				if (flag)
					tmpstring.append(",");
				tmpstring.append(tmps.trim());
				flag = true;
			}
			resultString = tmpstring.toString();
		}
		return resultString;
	}

	/**
	 * 根據以逗號分割的字符串參數轉換為去除逗號的數組
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Jul 7, 2009 10:45:56 AM<br>
	 *         <b>last modify Date:</b>Jul 7, 2009 10:45:56 AM<br>
	 * @param string
	 *            例如"1,2,3,4,5,6"
	 * @return String[]
	 */

	public static String[] string2Array(String string) {
		String[] tmpArray = null;
		if (string != null && !"".equals(string.trim())) {
			tmpArray = string.split(",");
		}
		return tmpArray;

	}

	/**
	 * 根據以逗號分割的字符串參數轉換為去除逗號的List<String>
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>Jul 7, 2009 10:45:59 AM<br>
	 *         <b>last modify Date:</b>Jul 7, 2009 10:45:59 AM<br>
	 * @param string
	 *            例如"1,2,3,4,5,6"
	 * @return List<String>
	 */

	public static List<String> string2List(String string) {
		List<String> tmpList = null;
		if (string != null && !"".equals(string.trim())) {
			tmpList = Arrays.asList(string.split(","));
		}
		return tmpList;
	}

	/**
	 * str转换为int 。null和""返回0;其余的返回int型。
	 * 
	 * @author zhangshiying<br>
	 *         <b>create Date:</b>2009/12/14 12:52:27<br>
	 *         <b>last modify Date:</b>2009/12/14 12:52:27<br>
	 * @param string
	 * @return int型。
	 */

	public static int str2Num(String str) {
		if (str == null || "".equals(str.trim())) {
			return 0;
		}
		return Integer.parseInt(str.trim());
	}

	/**
	 * 把val转换为固定小数位长的float，然后在返回float型的string
	 * 
	 * @author zhangshiying<br>
	 *         <b>create Date:</b>2009/12/14 13:33:04<br>
	 *         <b>last modify Date:</b>2009/12/14 13:33:04<br>
	 * @param val
	 *            要转换的值。
	 * @param s
	 *            小数位数
	 * @return
	 */

	public static String str2Float(String val, int s) {
		if (val == null)
			return null;
		Double number = Double.parseDouble(val);
		String strVal = str2Float(number, s);
		return strVal;
	}

	/**
	 * 把val转换为固定小数位长的float，然后在返回float型的string
	 * 
	 * @author zhangshiying<br>
	 *         <b>create Date:</b>2009/12/14 15:23:25<br>
	 *         <b>last modify Date:</b>2009/12/14 15:23:25<br>
	 * @param val
	 *            要转换的值。
	 * @param s
	 *            小数位数
	 * @return
	 */

	public static String str2Float(Double val, int s) {
		String strVal = "0";
		String temp = "0";
		for (int i = 0; i < s; i++) {
			if (i == 0) {
				temp = "0.0";
			} else {
				temp = temp.substring(0, temp.indexOf(".") + 1) + "0"
						+ temp.substring(temp.indexOf(".") + 1);
			}
		}
		DecimalFormat decimalFormat = new DecimalFormat(temp);
		strVal = decimalFormat.format(val);
		return strVal;

	}

	/**
	 * 例如：StringUtil.substring("richer",4) 得到的结果为：rich
	 * <p>
	 * 得到字符串指定长度字符
	 * 
	 * @param str
	 *            字符串
	 * @param len：
	 *            要得到的字符个数
	 * @return 截取后得到的字符
	 */
	public static String substring(String str, int len) {
		if (str == null || len < 1) {
			return null;
		} else if (str.length() < len) {
			return str;
		} else {
			return str.substring(0, len);
		}
	}

	public static String getEncode(String str) {
		// System.out.println(str);
		String strc = null;
		try {
			strc = new String(str.getBytes("ISO-8859-1"), "gb2312");
		} catch (UnsupportedEncodingException c) {

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		return strc;
	}

	/**
	 * 根据时间用于生成自定义文件 例如：StringUtil.formatDateHtml("2006-10-10
	 * 23:22:09",null)结果为：20061010232209 StringUtil.formatDateHtml("2006-10-10
	 * 23:22:09",".html")结果为：20061010232209.html
	 * <p>
	 * 用于生成随机的HTML文件
	 * 
	 * @param str
	 *            日期字符串
	 * @param s
	 *            文件的后缀名,注意前面加“.”
	 * 
	 * @return 返回格式化完成后的字符串
	 */
	public static String formatDateHtml(String str, String s) {
		StringBuffer re = new StringBuffer();
		java.util.StringTokenizer analysis = new java.util.StringTokenizer(str,
				"- :");
		while (analysis.hasMoreTokens()) {
			re.append(analysis.nextToken());
		}
		if (!(s == null)) {
			re.append(s);
		}
		return re.toString();
	}

	/**
	 * <p>
	 * 把字符打散转换成UTF-8的格式，用于解决网页上汉字乱码
	 * 
	 * @param str
	 *            字符串
	 * @return 截取后得到的字符
	 */

	public static String getEncodeStr(String str) {
		String strUtf8 = null;
		try {
			strUtf8 = new String(str.getBytes("ISO-8859-1"), "utf-8");
		} catch (UnsupportedEncodingException e) {

		}
		return strUtf8;
	}

	/**
	 * <p>
	 * 把字符打散转换成自定义的格式，用于解决网页上汉字乱码
	 * 
	 * @param str
	 *            字符串
	 * @param from
	 *            字符集名
	 * @param to
	 *            字符集名
	 * @return 截取后得到的字符
	 */

	public static String getEncodeStr(String str, String from, String to) {
		String strUtf8 = null;
		try {
			strUtf8 = new String(str.getBytes(from), to);
		} catch (UnsupportedEncodingException e) {

		}
		return strUtf8;
	}

	/**
	 * <p>
	 * 类似ORACLE中的nvl函数，如果str为空，就把d的值赋给str
	 * 
	 * @param str
	 *            字符串
	 * @param d
	 *            字符串
	 * @return
	 */
	public static String nvl(String str, String d) {
		return str == null ? d : str;
	}

	/**
	 * <p>
	 * 检查字符串是否为空或空白
	 * 
	 * @param param
	 *            字符串
	 * @return
	 */
	public static boolean isNullOrBlank(String param) {
		return (param == null || param.trim().equals("")) ? true : false;
	}

	/**
     * 判断数字
     * @author zhangshiying<br>
	 * <b>create Date:</b>2010/05/23 10:57:03<br>
	 * <b>last modify Date:</b>2010/05/23 10:57:03<br>
     * support Numeric format:<br>
     * "33" "+33" "033.30" "-.33" ".33" " 33." " 000.000 "
     * @param str String
     * @return boolean
     */
   public static boolean isNumeric(String str) {
       int begin = 0;
       boolean once = true;
       if (str == null || str.trim().equals("")) {
           return false;
       }
       str = str.trim();
       if (str.startsWith("+") || str.startsWith("-")) {
           if (str.length() == 1) {
               // "+" "-"
               return false;
           }
           begin = 1;
       }
       for (int i = begin; i < str.length(); i++) {
           if (!Character.isDigit(str.charAt(i))) {
               if (str.charAt(i) == '.' && once) {
                   // '.' can only once
                   once = false;
               }
               else {
                   return false;
               }
           }
       }
       if (str.length() == (begin + 1) && !once) {
           // "." "+." "-."
           return false;
       }
       return true;
   }

   /**
     * 判断整数
     * @author zhangshiying<br>
	 * <b>create Date:</b>2010/05/23 10:57:03<br>
	 * <b>last modify Date:</b>2010/05/23 10:57:03<br>
     * support Integer format:<br>
     * "33" "003300" "+33" " -0000 "
     * @param str String
     * @return boolean
     */

   public static boolean isInteger(String str) {
       int begin = 0;
       if (str == null || str.trim().equals("")) {
           return false;
       }
       str = str.trim();
       if (str.startsWith("+") || str.startsWith("-")) {
           if (str.length() == 1) {
               // "+" "-"
               return false;
           }
           begin = 1;
       }
       for (int i = begin; i < str.length(); i++) {
           if (!Character.isDigit(str.charAt(i))) {
               return false;
           }
       }
       return true;
   }


	/**
	 * 把String转换成int，JDK自带的有时候转换比较麻烦
	 */
	public static int parseInt(String param) {
		int i = 0;
		if (param == null || "".equals(param.trim()))
			return i;
		try {
			i = Integer.parseInt(param);
		} catch (Exception e) {
			try {
				i = (int) parseFloat(param);
			} catch (Exception te) {

			}
		}
		return i;
	}

	@SuppressWarnings("static-access")
	public static String setAddress(String str) {
		String st = "";
		char[] cha = str.toCharArray();
		for (int i = 0; i < cha.length; i++) {
			if (cha[i] == '?') {
				st = st + " ";
			} else {
				st = st + st.valueOf(cha[i]);
			}

		}
		return st;
	}

	public static long parseLong(String param) {
		long result = 0;
		if (param == null || "".equals(param.trim()))
			return result;
		if (param != null && !"".equals(param)) {
			try {
				result = Long.parseLong(param);
			} catch (Exception e) {

			}
		}
		return result;
	}

	public static int parseInteger(String param) {
		int result = 0;
		if (param == null || "".equals(param.trim()))
			return result;
		if (param != null && !"".equals(param)) {
			try {
				result = Integer.parseInt(param);
			} catch (Exception e) {

			}
		}
		return result;
	}

	public static double parseDouble(String param) {
		double result = 0;
		if (param == null || "".equals(param.trim()))
			return result;
		if (param != null && !"".equals(param)) {
			try {
				result = Double.parseDouble(param);
			} catch (Exception e) {

			}
		}
		return result;
	}

	public static float parseFloat(String param) {
		float result = 0;
		if (param == null || "".equals(param.trim()))
			return result;
		if (param != null && !"".equals(param)) {
			try {
				result = Float.parseFloat(param);
			} catch (Exception e) {

			}
		}
		return result;
	}

	private static char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz"
			+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();

	private static Random randGen = new Random();

	/**
	 * 例如：StringUtil.randomStr(5) 生成：Ja251
	 * <p>
	 * 生成一个指定长度的随机字符串，使用于做文件名
	 * 
	 * @param length
	 *            生成的长度
	 * @return
	 */
	public static final String randomStr(int length) {
		if (length < 1) {
			return null;
		}
		char[] randBuffer = new char[length];
		for (int i = 0; i < randBuffer.length; i++) {
			randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
		}
		return new String(randBuffer);
	}

	/**
	 * 例如：StringUtil.randomNum(5) 生成：06512
	 * <p>
	 * 生成一个指定长度的随机数，使用于做文件名
	 * 
	 * @param length
	 *            生成的长度
	 * @return
	 */
	public static final String randomNum(int length) {
		if (length < 1) {
			return null;
		}
		StringBuffer randBuffer = new StringBuffer();
		for (int i = 0; i < length; i++) {
			randBuffer.append(Integer.toString(randGen.nextInt(9)));
		}
		return randBuffer.toString();
	}

	/**
	 * 将半角的符号转换成全角符号
	 */
	public static String changeToFull(String str) {
		String source = "1234567890!@#$%^&*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_=+\\|[];:'\",<.>/?";
		String[] decode = { "１", "２", "３", "４", "５", "６", "７", "８", "９", "０",
				"！", "＠", "＃", "＄", "％", "︿", "＆", "＊", "（", "）", "ａ", "ｂ",
				"ｃ", "ｄ", "ｅ", "ｆ", "ｇ", "ｈ", "ｉ", "ｊ", "ｋ", "ｌ", "ｍ", "ｎ",
				"ｏ", "ｐ", "ｑ", "ｒ", "ｓ", "ｔ", "ｕ", "ｖ", "ｗ", "ｘ", "ｙ", "ｚ",
				"Ａ", "Ｂ", "Ｃ", "Ｄ", "Ｅ", "Ｆ", "Ｇ", "Ｈ", "Ｉ", "Ｊ", "Ｋ", "Ｌ",
				"Ｍ", "Ｎ", "Ｏ", "Ｐ", "Ｑ", "Ｒ", "Ｓ", "Ｔ", "Ｕ", "Ｖ", "Ｗ", "Ｘ",
				"Ｙ", "Ｚ", "－", "＿", "＝", "＋", "＼", "｜", "【", "】", "；", "：",
				"'", "\"", "，", "〈", "。", "〉", "／", "？" };

		String result = "";

		for (int i = 0; i < str.length(); i++) {
			int pos = source.indexOf(str.charAt(i));
			if (pos != -1) {
				result += decode[pos];
			} else {
				result += str.charAt(i);
			}
		}
		return result;
	}

	private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };

	private static String byteArrayToHexString(byte[] b) {
		StringBuffer resultSb = new StringBuffer();
		for (int i = 0; i < b.length; i++) {
			resultSb.append(byteToHexString(b[i]));
		}
		return resultSb.toString();
	}

	private static String byteToHexString(byte b) {
		int n = b;
		if (n < 0)
			n = 256 + n;
		int d1 = n / 16;
		int d2 = n % 16;
		return hexDigits[d1] + hexDigits[d2];
	}

	/**
	 * 例如：StringUtil.MD5("richer") 生成：43091a5955ffeb31300b99c81bf90094
	 * <p>
	 * 把字符串转换成MD5，使用于加密
	 * 
	 * @param origin
	 *            字符串
	 * @return
	 */
	public static String md5(String origin) {
		String resultString = null;

		try {
			resultString = new String(origin);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byteArrayToHexString(md.digest(resultString
					.getBytes()));
		} catch (Exception ex) {

		}
		return resultString;
	}

	private static final char[] zeroArray = "0000000000000000".toCharArray();

	/**
	 * 例如：StringUtil.zeroPadStr("1234",10) 生成：0000001234
	 * <p>
	 * 把字符串转换成指定长度，不够在前面补0，适用于数据库ID补位
	 * 
	 * @return
	 */
	public static final String zeroPadStr(String string, int length) {
		if (string == null || string.length() > length) {
			return string;
		}
		StringBuffer buf = new StringBuffer(length);
		buf.append(zeroArray, 0, length - string.length()).append(string);
		return buf.toString();
	}

	private static final char[] GT_ENCODE = "&gt;".toCharArray();

	private static final char[] LT_ENCODE = "&lt;".toCharArray();

	/**
	 * 例如：StringUtil.escapeHTMLTags("
	 * <P>
	 * richer
	 * </P>") 生成：&lt;P&gt;richer&lt;/P&gt;
	 * <p>
	 * 把HTML中的字符进行转换，适用于网页
	 * 
	 * @param in
	 *            字符串
	 * @return
	 */
	public static final String escapeHTMLTags(String in) {
		if (in == null) {
			return null;
		}
		char ch;
		int i = 0;
		int last = 0;
		char[] input = in.toCharArray();
		int len = input.length;
		StringBuffer out = new StringBuffer((int) (len * 1.3));
		for (; i < len; i++) {
			ch = input[i];
			if (ch > '>') {
				continue;
			} else if (ch == '<') {
				if (i > last) {
					out.append(input, last, i - last);
				}
				last = i + 1;
				out.append(LT_ENCODE);
			} else if (ch == '>') {
				if (i > last) {
					out.append(input, last, i - last);
				}
				last = i + 1;
				out.append(GT_ENCODE);
			}
		}
		if (last == 0) {
			return in;
		}
		if (i > last) {
			out.append(input, last, i - last);
		}
		return out.toString();
	}

	private static final String cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			+ "abcdefghijklmnopqrstuvwxyz" + "0123456789+/";
	private static final int fillchar = '=';

	private static String encodeBase64(byte[] data) {
		int c;
		int len = data.length;
		StringBuffer ret = new StringBuffer(((len / 3) + 1) * 4);
		for (int i = 0; i < len; ++i) {
			c = (data[i] >> 2) & 0x3f;
			ret.append(cvt.charAt(c));
			c = (data[i] << 4) & 0x3f;
			if (++i < len)
				c |= (data[i] >> 4) & 0x0f;

			ret.append(cvt.charAt(c));
			if (i < len) {
				c = (data[i] << 2) & 0x3f;
				if (++i < len)
					c |= (data[i] >> 6) & 0x03;

				ret.append(cvt.charAt(c));
			} else {
				++i;
				ret.append((char) fillchar);
			}

			if (i < len) {
				c = data[i] & 0x3f;
				ret.append(cvt.charAt(c));
			} else {
				ret.append((char) fillchar);
			}
		}
		return ret.toString();
	}

	/**
	 * 把一个字符串转换成64位编码
	 * 
	 * @param data
	 *            字符
	 * @return
	 */
	public static String encodeBase64(String data) {
		return encodeBase64(data.getBytes());
	}

	public static final String replace(String line, String oldString,
			String newString) {
		if (line == null) {
			return null;
		}
		int i = 0;
		if ((i = line.indexOf(oldString, i)) >= 0) {
			char[] line2 = line.toCharArray();
			char[] newString2 = newString.toCharArray();
			int oLength = oldString.length();
			StringBuffer buf = new StringBuffer(line2.length);
			buf.append(line2, 0, i).append(newString2);
			i += oLength;
			int j = i;
			while ((i = line.indexOf(oldString, i)) > 0) {
				buf.append(line2, j, i - j).append(newString2);
				i += oLength;
				j = i;
			}
			buf.append(line2, j, line2.length - j);
			return buf.toString();
		}
		return line;
	}

	public static String getEncodeStrl(String str) {
		String strUtf8 = null;
		try {
			strUtf8 = new String(str.getBytes("ISO-8859-1"), "gb2312");
		} catch (UnsupportedEncodingException e) {

		}
		return strUtf8;
	}

	/**
	 * 空值转换为"";
	 * 
	 * @author zhangshiying<br>
	 *         <b>create Date:</b>Aug 1, 2009 4:55:46 PM<br>
	 *         <b>last modify Date:</b>Aug 1, 2009 4:55:46 PM<br>
	 * @param str
	 * @return
	 */

	public static String nullChange(String str) {
		if (str == null)
			return "";
		else
			return str;

	}

	/**
	 * ""转换为空值;
	 * 
	 * @author daiyunchuan<br>
	 *         <b>create Date:</b>Nov 9, 2008 3:20:22 PM<br>
	 *         <b>last modify Date:</b>Nov 9, 2008 3:20:22 PM<br>
	 * @param str
	 * @return
	 */
	public static String emptyChange(String str) {
		if (str == null || str.equals(""))
			return null;
		else
			return str;

	}

	public static String encodeISO885912UTF8(String iso) {
		if (iso != null) {
			try {
				return new String(iso.getBytes("UTF-8"), "ISO8859-1");
			} catch (UnsupportedEncodingException e) {
			}
		}
		return "";
	}

	public static Object getStringBaseDataType(String data) {
		if (data != null) {
			try {
				Integer intdata = Integer.parseInt(data);
				return intdata;
			} catch (Exception inte) {
				try {
					Long longdata = Long.parseLong(data);
					return longdata;
				} catch (Exception longe) {
					try {
						Double doubledata = Double.parseDouble(data);
						return doubledata;
					} catch (Exception doublee) {
						return data;
					}
				}
			}

		}
		return data;

	}

	public static String getDataType(Object obj) {
		if (obj != null) {
			if (obj instanceof String)
				return "String";
			if (obj instanceof Integer)
				return "Integer";
			if (obj instanceof Long)
				return "Long";
			if (obj instanceof Float)
				return "Float";
			if (obj instanceof Double)
				return "Double";
		} else {
			return "null";
		}
		return "";
	}

	public static boolean equalWithTrim(String first, String second) {
		boolean flag = false;
		if (first != null) {
			if (second != null) {
				flag = first.trim().equals(second.trim());
			}
		} else {
			if (second == null) {
				flag = true;
			}
		}

		return flag;
	}

	/**
	 * @author jiangxc<br>
	 *         <b>create Date:</b>2010/04/12 14:25:43<br>
	 *         <b>last modify Date:</b>2010/04/12 14:25:43<br>
	 * @param resultList
	 * @return
	 */

	public static Long sumWithList(List<String> resultList) {
		long result = 0;
		if (resultList != null) {
			for (String tmp : resultList) {
				if (tmp != null || "".equals(tmp))
					result += Long.parseLong(tmp.trim());
			}
		}
		return result;
	}
	public static Integer sumWithListInteger(List<String> resultList) {
		int result = 0;
		if (resultList != null) {
			for (String tmp : resultList) {
				if (tmp != null || "".equals(tmp))
					result += Integer.parseInt(tmp.trim());
			}
		}
		return result;
	}
	/**
	 * 如果tmpstr为null则返回"null",否则返回tmpstr
	 * 
	 * @author jiangxc<br>
	 *         <b>create Date:</b>2010/04/16 13:39:04<br>
	 *         <b>last modify Date:</b>2010/04/16 13:39:04<br>
	 * @param tmpstr
	 * @return
	 */
	public static String replaceNullToStringNull(String tmpstr) {
		if (tmpstr == null || "".equals(tmpstr))
			return "NULL";
		else
			return tmpstr;
	}

	/**
	 * 将sr分割成特定的字符串
	 * 如sr为"001002003004005006007008009010011012"
	 * splitNum为3
	 * befappendString为"("
	 * aftappendString为")"
	 * douhaoFlag true时添加,  false时不添加,
	 * true 则结果为"(001),(002),(003),(004),(005),(006),(007),(008),(009),(010),(011),(012)"
	 * false 则结果为"(001)(002)(003)(004)(005)(006)(007)(008)(009)(010)(011)(012)"
	 * @author jiangxc<br>
	 * <b>create Date:</b>2010/04/20 13:49:46<br>
	 * <b>last modify Date:</b>2010/04/20 13:49:46<br>
	 * @param sr
	 * @param splitNum
	 * @param befappendString
	 * @param aftappendString
	 * @return
	 */
	
	public static String splitAndAppend(String sr, int splitNum,
			String befappendString, String aftappendString,boolean douhaoFlag) {
		String resultstr = "";
		if (sr != null && !"".equals(sr)) {
			StringBuffer sb = new StringBuffer();

			for (int i = 0; i < sr.length(); i++) {
				if (i == 0) {
					sb.append(befappendString);
				} else if (i % splitNum == 0) {
					if (aftappendString == null) {
						sb.append(befappendString);
						if(douhaoFlag)sb.append(",");
						sb.append(befappendString);
					} else {
						sb.append(aftappendString);
						if(douhaoFlag)sb.append(",");
						sb.append(befappendString);
					}
				}
				sb.append(sr.charAt(i));

				if (i + 1 == sr.length()) {
					sb.append(aftappendString);

				}
			}
			resultstr = sb.toString();
		} else {
			resultstr = sr;
		}

		return resultstr;
	}
	
	/**
	 * 将sr分割成特定的字符串
	 * 如sr为"001002003004005006007008009010011012"
	 * splitNum为3
	 * befappendString为"("
	 * aftappendString为")"
	 * midStr为, 
	 * 结果为"(001),(002),(003),(004),(005),(006),(007),(008),(009),(010),(011),(012)"
	 * @author jiangxc<br>
	 * <b>create Date:</b>2010/04/20 13:49:46<br>
	 * <b>last modify Date:</b>2010/04/20 13:49:46<br>
	 * @param sr
	 * @param splitNum
	 * @param befappendString
	 * @param aftappendString
	 * @return
	 */
	
	public static String splitAndAppend(String sr, int splitNum,
			String befappendString, String aftappendString,String midStr) {
		String resultstr = "";
		if (sr != null && !"".equals(sr)) {
			StringBuffer sb = new StringBuffer();

			for (int i = 0; i < sr.length(); i++) {
				if (i == 0) {
					sb.append(befappendString);
				} else if (i % splitNum == 0) {
					if (aftappendString == null) {
						sb.append(befappendString);
						sb.append(midStr);
						sb.append(befappendString);
					} else {
						sb.append(aftappendString);
						sb.append(midStr);
						sb.append(befappendString);
					}
				}
				sb.append(sr.charAt(i));

				if (i + 1 == sr.length()) {
					sb.append(aftappendString);

				}
			}
			resultstr = sb.toString();
		} else {
			resultstr = sr;
		}

		return resultstr;
	}
	/**
	 * 将sr分割成特定的字符串
	 * 如sr为"001002003004005006007008009010011012"
	 * splitNum为3
	 * appendString为","
	 * 则结果为"001,002,003,004,005,006,007,008,009,010,011,012"
	 * @author jiangxc<br>
	 * <b>create Date:</b>2010/04/20 13:53:05<br>
	 * <b>last modify Date:</b>2010/04/20 13:53:05<br>
	 * @param sr
	 * @param splitNum
	 * @param appendString
	 * @return
	 */
	
	public static String splitAndAppend(String sr, int splitNum,
			String appendString) {
		String resultstr = "";
		if (sr != null && !"".equals(sr)) {
			StringBuffer sb = new StringBuffer();

			for (int i = 0; i < sr.length(); i++) {
				
				if (i % splitNum == 0) {
					sb.append(appendString);
				}
				sb.append(sr.charAt(i));

			}
			resultstr = sb.toString();
		} else {
			resultstr = sr;
		}

		return resultstr;
	}
	
	/**
	 * @param data
	 * @param dotsize 保留几位小数
	 * @return
	 */
	public static String getDoubleRound(String data,int dotsize){
		if(StringUtil.isNullOrBlank(data))return data;
		String result="";
		Double doub=StringUtil.parseDouble(data);
		BigDecimal  b=new   BigDecimal(doub);   
		doub=b.setScale(dotsize,BigDecimal.ROUND_HALF_UP).doubleValue();
		result=String.valueOf(doub);
		return result;
	}

	public static void main(String[] args) {

		// String tmp = "123456";
		// String tmp1 = "123";
		// System.out.println("cutLeft------" + cutLeft(tmp, 4));
		// System.out.println("cutLeft------" + cutLeft(tmp1, 4));
		// System.out.println("cutRitht------" + cutRitht(tmp, 4));
		// System.out.println("cutRitht------" + cutRitht(tmp1, 4));
		// System.out.println("formatNumber------" + formatNumber(1, 4));
		String tmp = "001002003004005006007008009010011012";
		System.out.println(splitAndAppend(tmp, 3, "(", ")",","));
		List<String> tp = new ArrayList<String>();
		tp.add("1");
		tp.add("14");
		tp.add("100");
		tp.add("1000");
		tp.add("10000");
		System.out.println(sumWithList(tp));
		System.out.println(getDataType(getStringBaseDataType("10")));
		System.out.println(getDataType(getStringBaseDataType("10.4145")));
		System.out
				.println(getDataType(getStringBaseDataType("4564564646464410.4144666666666666666645")));
		System.out
				.println(getDataType(getStringBaseDataType("4564564646464410")));
	}
}

